﻿namespace Sidvall.WorkItemManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class WorkItemLog : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.WorkItemManager.Data.IWorkItemLog
    {
        #region Public Members

        #region ExecutionEndTime

        private System.DateTime _ExecutionEndTime;
        partial void OnBeforeExecutionEndTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData);
        partial void OnAfterExecutionEndTimePropertyChanged();
        public System.DateTime ExecutionEndTime
        { 
            get
            {
                return _ExecutionEndTime;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ExecutionEndTime = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData = new Sidvall.Business.PropertyChangeEventData<System.DateTime>(value, _ExecutionEndTime);
                    OnBeforeExecutionEndTimePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ExecutionEndTime", eventData.Value, true, true);
                        OnAfterExecutionEndTimePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ExecutionStartTime

        private System.DateTime _ExecutionStartTime;
        partial void OnBeforeExecutionStartTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData);
        partial void OnAfterExecutionStartTimePropertyChanged();
        public System.DateTime ExecutionStartTime
        { 
            get
            {
                return _ExecutionStartTime;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ExecutionStartTime = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData = new Sidvall.Business.PropertyChangeEventData<System.DateTime>(value, _ExecutionStartTime);
                    OnBeforeExecutionStartTimePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ExecutionStartTime", eventData.Value, true, true);
                        OnAfterExecutionStartTimePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ResultMessage

        private string _ResultMessage;
        partial void OnBeforeResultMessagePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterResultMessagePropertyChanged();
        public string ResultMessage
        { 
            get
            {
                return _ResultMessage;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ResultMessage = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _ResultMessage);
                    OnBeforeResultMessagePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ResultMessage", eventData.Value, true, true);
                        OnAfterResultMessagePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region WorkItemId

        private long _WorkItemId;
        partial void OnBeforeWorkItemIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<long> eventData);
        partial void OnAfterWorkItemIdPropertyChanged();
        public long WorkItemId
        { 
            get
            {
                return _WorkItemId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _WorkItemId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<long> eventData = new Sidvall.Business.PropertyChangeEventData<long>(value, _WorkItemId);
                    OnBeforeWorkItemIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("WorkItemId", eventData.Value, true, true);
                        OnAfterWorkItemIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region WorkItemLogId

        private System.Nullable<long> _WorkItemLogId;
        partial void OnBeforeWorkItemLogIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData);
        partial void OnAfterWorkItemLogIdPropertyChanged();
        public System.Nullable<long> WorkItemLogId
        { 
            get
            {
                return _WorkItemLogId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _WorkItemLogId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<long>>(value, _WorkItemLogId);
                    OnBeforeWorkItemLogIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("WorkItemLogId", eventData.Value, true, true);
                        OnAfterWorkItemLogIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region WorkItemResultId

        private global::Sidvall.WorkItemManager.Workflow.WorkItemResultType _WorkItemResultId;
        partial void OnBeforeWorkItemResultIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.WorkItemResultType> eventData);
        partial void OnAfterWorkItemResultIdPropertyChanged();
        public global::Sidvall.WorkItemManager.Workflow.WorkItemResultType WorkItemResultId
        { 
            get
            {
                return _WorkItemResultId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _WorkItemResultId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.WorkItemResultType> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.WorkItemResultType>(value, _WorkItemResultId);
                    OnBeforeWorkItemResultIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("WorkItemResultId", eventData.Value, true, true);
                        OnAfterWorkItemResultIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemLogManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemLogManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        public WorkItem WorkItem { get; set; }
        #region LoadWorkItemAsync

        public async System.Threading.Tasks.Task<WorkItem> LoadWorkItemAsync()
        {
            return await LoadWorkItemAsync(false, true, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<WorkItem> LoadWorkItemAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.WorkItemManager.Data.Fields.WorkItemField, global::Sidvall.WorkItemManager.Data.Relations.WorkItemRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.WorkItemManager.SystemContext.Current.DataPortal.WorkItemLogManager.LoadWorkItemAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters).ConfigureAwait(false);

            return this.WorkItem;
        }
        public WorkItem LoadWorkItem(WorkItem item)
        {
            LoadInstanceField("WorkItem", item, true, false);
            return item;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemLogManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public WorkItemLog Copy()
        {
            return global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemLogManager.Copy(this);
        }
        public WorkItemLog Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemLogManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.WorkItemManager.Data.IWorkItemLog item)
        {
            global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemLogManager.Import(this, item);
        }
        public void Import(global::Sidvall.WorkItemManager.Data.IWorkItemLog item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemLogManager.Import(this, item, settings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<WorkItemLog> SaveItemAsync()
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.DataPortal.WorkItemLogManager.SaveItemAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<WorkItemLog> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.DataPortal.WorkItemLogManager.SaveItemAsync(this, mode).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<WorkItemLog> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.DataPortal.WorkItemLogManager.SaveItemAsync(this, settings).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<WorkItemLog> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.DataPortal.WorkItemLogManager.SaveItemAsync(this, settings, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemLogManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemLogManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemLogManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemLogManager.Initialize(this, settings);
        }

        #endregion

        #region IWorkItemLog Members

        System.DateTime global::Sidvall.WorkItemManager.Data.IWorkItemLog.ExecutionEndTime
        {
            get
            {
                return this._ExecutionEndTime;
            }
            set
            {
                this._ExecutionEndTime = value;
            }
        }
        System.DateTime global::Sidvall.WorkItemManager.Data.IWorkItemLog.ExecutionStartTime
        {
            get
            {
                return this._ExecutionStartTime;
            }
            set
            {
                this._ExecutionStartTime = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IWorkItemLog.ResultMessage
        {
            get
            {
                return this._ResultMessage;
            }
            set
            {
                this._ResultMessage = value;
            }
        }
        long global::Sidvall.WorkItemManager.Data.IWorkItemLog.WorkItemId
        {
            get
            {
                return this._WorkItemId;
            }
            set
            {
                this._WorkItemId = value;
            }
        }
        System.Nullable<long> global::Sidvall.WorkItemManager.Data.IWorkItemLog.WorkItemLogId
        {
            get
            {
                return this._WorkItemLogId;
            }
            set
            {
                this._WorkItemLogId = value;
            }
        }
        global::Sidvall.WorkItemManager.Workflow.WorkItemResultType global::Sidvall.WorkItemManager.Data.IWorkItemLog.WorkItemResultId
        {
            get
            {
                return this._WorkItemResultId;
            }
            set
            {
                this._WorkItemResultId = value;
            }
        }
        global::Sidvall.WorkItemManager.Data.IWorkItem global::Sidvall.WorkItemManager.Data.IWorkItemLog.WorkItem
        {
            get
            {
                return this.WorkItem;
            }
            set
            {
                this.WorkItem = (WorkItem)value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public WorkItemLog()
        {
        }
        public WorkItemLog(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public WorkItemLog(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemLogManager.Initialize(this);
        }

        #endregion
    }
}